var KS = {};
(function(){
	//tab
	KS.Tab = function(tabid){
		this.tabs  = $("#"+tabid).children();
		this._bindTabEvents()
	}
	KS.Tab.prototype = {
		_bindTabEvents:function(){
			var _this = this;
			this.tabs.click(function(){
					_this.select(this)
				})
		},
		select:function(tab){
			var tab = ('string' == typeof tab)?$("#"+tab):$(tab)
			this.tabs.removeClass("select");
			tab.addClass("select")
		}
	}
	//list	
	KS.List = function(boxid,s){
		KS.Tab.call(this,boxid)
		this.lists = this.tabs;//继承至KS.Tab
		this.s = s;
		this._bindlistEvents()
	}
	KS.List.prototype = new KS.Tab();
	KS.List.prototype._bindTabEvents = function(){}
	KS.List.prototype._bindlistEvents = function(){
			var _this = this;
			_this.lists.unbind();
			_this.lists.hover(function(){
					$(this).addClass("hover")
				},function(){
					$(this).removeClass("hover")
					}).click(function(){
					$(this).removeClass("hover")
					if(_this.s){
						_this.select(this)//继承至KS.Tab
					}
				}).filter(":odd").addClass("even")

	}

	//window
	KS.Window = function(){
		this._init()
	}
	KS.Window.prototype  = {
		_init:function(){
			var _this = this;
			$(document.body).append('<div id="admin-window"><h1><span id="admin-window-close"><img src="../../skin/default/close.png" /></span><b id="admin-window-title"></b></h1><div id="admin-window-content">数据加载中...</div></div>');
			$("#admin-window-close").click(function(){
					try{
					if(kaohao){
						kaohao.CloseSuggext()
					}
					}
					catch(e){}
					_this.close()
				})
		},
		open:function(options){
			try{
			window.event.cancelBubble = true;
			}
			catch(e){}
			var _this = this;
			_this.opt = $.extend({
					title:"编辑窗口",
					width:"375",
					url:""
				},options)
			$("#admin-window-title").html(_this.opt.title);
			$.blockUI({ message: $("#admin-window") ,css:{
				"marginLeft":-_this.opt.width/2,
				"width":_this.opt.width
			}});
			_this._loadurl(_this.opt.url);
		},
		close:function(){
			$("#admin-window-content").html("数据加载中...");
			$.unblockUI();
		},
		_loadurl:function(url){
			var _this = this;
			$.ajax({
			  type: "GET",
			  url: url,
			  data:"s="+Math.random(),
			  success:function(msg){
			  	$("#admin-window-content").html(msg);
			  	window.setTimeout(function(){
			  		$("#admin-window-content").find("input[type='text']:first").focus()
			  		},100)
			  	
			  },
			  error:function(){
			  	$("#admin-window-content").html("<span style='color:red'>数据调用出错，请刷新页面重试</span>")
			  }
			}); 
		}
	}
	
	KS.contorlpanel = function(){
		this._init()
	}
	
	KS.contorlpanel.prototype = {
		_init:function(){
			this.panels = $(".panel");
			this.panelh1s = this.panels.find("h1");
			this.panelh1btns = this.panelh1s.find("span");
			
			this._bindHoverEvents(this.panels)
			this._bindHoverEvents(this.panelh1btns)
			this.panels.hover(function(){
				$(this).find("h1 span").show()
				},function(){
				$(this).find("h1 span").hide()
				})

		},
		_bindHoverEvents:function(allobj){
			allobj.hover(function(){
				$(this).addClass("hover")
				},function(){
				$(this).removeClass("hover")
				})
		},
		LoadStatus:function(url){
			var _this = this;
			$.ajax({
			  type: "GET",
			  url: url,
			  data:"s="+Math.random(),
			  success:function(msg){
			  	var statusArray = $.trim(msg).split(",")
			  	_this.panels.each(function(i){
			  			$(this).removeClass("status-1").removeClass("status-2").removeClass("status-3").removeClass("status-4").removeClass("status-5")
			  			$(this).addClass("status-"+statusArray[i]+"")
			  		})
			  },
			  error:function(){
			  	
			  }
			});
		}
	}

	KS.print = function(url){
		var height = 720;
		var width = 1024;
		window.open (url, 'newwindow', 'height='+height+', width='+width+',toolbar=no, menubar=yes, scrollbars=yes, resizable=yes,location=no, status=no,left=50%,top=0')
	}



})()
